package br.com.cpqd.ssar.utilitarias;

import java.util.LinkedList;

public class Cone extends AtributosGeometria {

    private float height;
    private float radius;
    private LinkedList listVertex = new LinkedList();
    private LinkedList listTriangles = new LinkedList();
    private Triangulo[] listaTriangulos = null;

    public Cone(float radius, float height, float[] reference, int id) {

        super(reference, id);
        this.height = height;
        this.radius = radius;
    }

    public float getAltura() {
        return height;
    }

    public void setAltura(float height) {
        this.height = height;
    }

    public float getRaio() {
        return radius;
    }

    public void setRaio(float radius) {
        this.radius = radius;
    }

    public Triangulo[] triangularizarGeometria() {
        listTriangles.clear();
        listVertex.clear();
        float x = 0, y = 0, angle; // Storage for coordinates and angles

        float GL_PI = 3.1415f;
        float h = radius;
        float raio = height;

        //vertex = new Vertice(0.0f+this.getXBegin(), 0.0f+this.getYBegin(),0.0f+this.getZBegin());
        Vertice vertexCentro = new Vertice(referencial);
        listVertex.add(vertexCentro); //vertice do centro

        // Loop around in a circle and specify even points along the circle
        // as the vertices of the triangle fan
        for (angle = 0.0f; angle < (2.0f * GL_PI); angle += (GL_PI / 8.0f)) {
            // Calculate x and y position of the next vertex
            x = (float) (raio * Math.sin(angle));
            y = (float) (raio * Math.cos(angle));
            // Specify the next vertex for the triangle fan
            //adicionando vertice no objeto cone2
            float[] coordenada = new float[3];
            coordenada[0] = referencial[0] + x;
            coordenada[1] = referencial[1] + y;
            coordenada[2] = referencial[2] + 0;
            Vertice vertex = new Vertice(coordenada);

            //vertex = new Vertice(x+this.getXBegin(), y+this.getYBegin(), zFinal+this.getZBegin());
            listVertex.add(vertex);


        }

        //vertice da altura
        float[] coordenada = new float[3];
        coordenada[0] = referencial[0] + x;
        coordenada[1] = referencial[1] + y;
        coordenada[2] = h + referencial[2];
        Vertice vertexAltura = new Vertice(coordenada);
        coordenada = new float[3];
        //vertex = new Vertice(0.0f + this.getXBegin(), 0.0f + this.getYBegin(), height + this.getZBegin());
        listVertex.add(vertexAltura);

        /* triangularizando a base do cone  */
        Vertice vertexBase = (Vertice) listVertex.get(0); //recebe o vertice 0 (centro)

        for (int i = 1; i < 16; i++) {
            Vertice vertexAux = (Vertice) listVertex.get(i);
            Vertice vertexAux2 = (Vertice) listVertex.get(i + 1);
            //calculando a normal dos 3 vertices
            float[] vectorNormal = super.calcVetorNormal(vertexBase, vertexAux, vertexAux2);
            Vertice[] vectorV = new Vertice[3];
            vectorV[0] = vertexBase;
            vectorV[1] = vertexAux;
            vectorV[2] = vertexAux2;
            Triangulo triangleFace = new Triangulo(vectorV, vectorNormal);
            listTriangles.add(triangleFace);
        }
        /* triangularizando os lados do cone */
        Vertice vertexLado = (Vertice) listVertex.get(18); //recebe o vertice 0 (centro)

        vertexLado.setCoordenada(2, h);
        vertexLado.setCoordenada(1, referencial[1]);
        vertexLado.setCoordenada(0, referencial[0]);
        vertexLado = (Vertice) listVertex.get(18); //recebe o vertice 0 (centro)

        for (int i = 1; i < 16; i++) {
            Vertice vertexAux = (Vertice) listVertex.get(i);
            Vertice vertexAux2 = (Vertice) listVertex.get(i + 1);
            //calculando a normal dos 3 vertices
            float[] vectorNormal = super.calcVetorNormal(vertexLado, vertexAux, vertexAux2);
            Vertice[] vectorV = new Vertice[3];
            vectorV[0] = vertexLado;
            vectorV[1] = vertexAux;
            vectorV[2] = vertexAux2;
            Triangulo triangleFace = new Triangulo(vectorV, vectorNormal);
            listTriangles.add(triangleFace);
        }
        /* triangularizando a ultima face do cone */
        Vertice vertexAux = (Vertice) listVertex.get(16);
        Vertice vertexAux2 = (Vertice) listVertex.get(1);
        //calculando a normal dos 3 vertices
        float[] vectorNormal = super.calcVetorNormal(vertexLado, vertexAux, vertexAux2);
        Vertice[] vectorV = new Vertice[3];
        vectorV[0] = vertexLado;
        vectorV[1] = vertexAux;
        vectorV[2] = vertexAux2;
        Triangulo triangleFace = new Triangulo(vectorV, vectorNormal);
        vectorV = new Vertice[3];
        vectorNormal = new float[3];
        listTriangles.add(triangleFace);

        listaTriangulos = new Triangulo[listTriangles.size()];
        for (int i = 0; i < listTriangles.size(); i++) {
            listaTriangulos[i] = (Triangulo) listTriangles.get(i);
        }
        return listaTriangulos;

    }

    @Override
    public float[] getFirsPoint() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public float[] getSecondPoint() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setSecondPoint(float[] secondPoint) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setFirsPoint(float[] firstPoint) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoX() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoX(int discretizacaoX) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoY() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoY(int discretizacaoY) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getDiscretizacaoZ() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setDiscretizacaoZ(int discretizacaoZ) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDx() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDy() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getDz() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlXi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlXi(int pmlXi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlXf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlXf(int pmlXf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlYi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlYi(int pmlYi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlYf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlYf(int pmlYf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlZi() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlZi(int pmlZi) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getPmlZf() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setPmlZf(int pmlZf) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public double getEscala() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setEscala(double escala) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setEscala(String tipo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addX() {
        this.referencial[0] += 1;
    }

    @Override
    public void addY() {
        referencial[1] += 1;
    }

    @Override
    public void addZ() {
        referencial[2] += 1;
    }

    @Override
    public void subX() {
        this.referencial[0] -= 1;
    }

    @Override
    public void subY() {
        referencial[1] -= 1;
    }

    @Override
    public void subZ() {
        referencial[2] -= 1;
    }

    @Override
    public void redimensionar() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getCaminhoArquivo() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setCaminhoArquivo(String caminhoArquivo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getNSteps() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addX(float valor) {
        this.referencial[0] += valor;
    }

    @Override
    public void addY(float valor) {
         this.referencial[1] += valor;
    }

    @Override
    public void addZ(float valor) {
         this.referencial[2] += valor;
    }  
  

    @Override
    public void setNElements(int n){
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getNElements(){
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Triangulo[] getListaTriangulosSTL(){
        throw new UnsupportedOperationException("Not supported yet.");
    }


    @Override
    public void redimensionarSTL(float[] min, float[] max){
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void subX(float valor) {
    this.referencial[0] -= valor;
    }

    @Override
    public void subY(float valor) {
       this.referencial[1] -= valor;
    }

    @Override
    public void subZ(float valor) {
       this.referencial[2] -= valor;
    }
}
